import {
  getIntroduceList,
  editIntroduceList
} from '@/api/introduce'

const state = {
  introduceData: {},
  introduceRow: {}
}

const mutations = {
  GET_INTRODUCE_DATA: (state, data) => {
    state.introduceData = data
  },
  GET_INTRODUCE_ROW: (state, data) => {
    state.introduceRow = data
  }
}

const actions = {
  async getIntroduceData({ commit }, playload) {
    let data = {}
    let newData = []
    let introData = []
    const list = null
    if (Object.keys(playload).length > 0) {
      data = playload
    }
    const resp = await getIntroduceList(data)
    const host = resp.data.host
    newData = [...newData, ...resp.data.data.rows]
    newData[0].host = host
    introData = [...newData, ...resp.data.data.rows]
    introData[0].host = host
    commit('GET_INTRODUCE_DATA', newData[0])
    return resp
  },
  async editIntroduceData({ commit }, playload) {
    const resp = await editIntroduceList(playload)
    return resp
  },
  async getIntroduceRow({ commit }, playload) {
    let data = {}
    let newData = []
    const introData = []
    const list = null
    if (Object.keys(playload).length > 0) {
      data = playload
    }
    const resp = await getIntroduceList(data)
    const host = resp.data.host
    newData = [...newData, ...resp.data.data.rows]
    newData[0].host = host
    commit('GET_INTRODUCE_ROW', newData[0])
    return resp
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
